<template>
  <div class="user-wrapper" :class="theme">
    <span class="action">
      <a class="logout_title" target="_blank" href="http://jeecg-boot.mydoc.io">
        <a-icon type="clock-circle"></a-icon>
      </a>
    </span>
    <span class="action">
      <a class="logout_title" target="_blank" href="http://jeecg-boot.mydoc.io">
        <a-icon type="question-circle-o"></a-icon>
      </a>
    </span>
    <header-notice class="action" />
    <a-dropdown>
      <span class="action action-full ant-dropdown-link user-dropdown-menu">
        <a-icon type="user" />
      </span>
      <a-menu slot="overlay" class="user-dropdown-menu-wrapper">
        <a-menu-item key="0">
          <router-link :to="{ name: 'account-center' }">
            <a-icon type="user" />
            <span>个人信息</span>
          </router-link>
        </a-menu-item>
        <a-menu-item key="1">
          <router-link :to="{ name: 'account-settings-base' }">
            <a-icon type="setting" />
            <span>修改密码</span>
          </router-link>
        </a-menu-item>
        <a-menu-item key="3" @click="handleLogout">
          <a-icon type="logout" />
          <span>退出登陆</span>
        </a-menu-item>
        <!-- <a-menu-item key="2" disabled>
          <a-icon type="setting"/>
          <span>测试</span>
        </a-menu-item>
        <a-menu-divider/>
        <a-menu-item key="3">
          <a href="javascript:;" @click="handleLogout">
            <a-icon type="logout"/>
            <span>退出登录</span>
          </a>
        </a-menu-item>-->
      </a-menu>
    </a-dropdown>
  </div>
</template>

<script>
import HeaderNotice from './HeaderNotice'
import UserPassword from './UserPassword'
import SettingDrawer from '@/components/setting/SettingDrawer'
import DepartSelect from './DepartSelect'
import { mapActions, mapGetters } from 'vuex'
import { mixinDevice } from '@/utils/mixin.js'

export default {
  name: 'UserMenu',
  mixins: [mixinDevice],
  components: {
    HeaderNotice,
    UserPassword,
    DepartSelect,
    SettingDrawer
  },
  props: {
    theme: {
      type: String,
      required: false,
      default: 'dark'
    }
  },
  methods: {
    ...mapActions(['Logout']),
    ...mapGetters(['nickname', 'avatar', 'userInfo']),
    getAvatar() {
      console.log('url = ' + window._CONFIG['imgDomainURL'] + '/' + this.avatar())
      return window._CONFIG['imgDomainURL'] + '/' + this.avatar()
    },
    handleLogout() {
      //修改源代码，并且取消退出弹框
      this.Logout({})
        .then(() => {
          window.location.href = '/'
          //window.location.reload()
        })
        .catch(err => {
          that.$message.error({
            title: '错误',
            description: err.message
          })
        })
    },
    onCancel() {}
  },
  updatePassword() {
    let username = this.userInfo().username
    this.$refs.userPassword.show(username)
  },
  updateCurrentDepart() {
    this.$refs.departSelect.show()
  },
  systemSetting() {
    this.$refs.settingDrawer.showDrawer()
  }
}
</script>

<style scoped>
.logout_title {
  color: inherit;
  text-decoration: none;
}
</style>